Why are the binary attributes defined as "Int" for Photo in person object
Hello,

I am trying to use this client to set binary attributes such as Photo in FIM but found out that these attributes were defined as "Int' in the client schema instead of "Byte[]".

What is the reason for that?

Does anybody has some sample code to set binary attributes in FIM?



 I am trying to use this client to set binary attributes such as Photo in FIM but found out that these attributes were defined as "Int' in the client schema instead of "Byte[]".

I am writing a WCF service which upload a photo to the FIM but i having issues wit the attribute as it is int.
Here is my code:

 public UploadedFile Upload(Stream Uploading)
        {
            int length = 0;
            UploadedFile upload = new UploadedFile { FilePath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()) };

            // This  shows the basic steps to modify a resource.
            using (DefaultClient client = new DefaultClient())
            {
                string filterName = "/Person[AccountName='" + HttpContext.Current.User.Identity.Name.Split('\\')[1].ToString() + "']";
                System.Security.Principal.WindowsImpersonationContext ctx = null;
                ctx = ((System.Security.Principal.WindowsIdentity)HttpContext.Current.User.Identity).Impersonate();

                //set credentials and refresh schema
                client.RefreshSchema();

                // get the person(s) object(s) to modify
                foreach (RmPerson person in client.Enumerate(filterName))
                {
                    // create the object to track changes to the resource
                    RmResourceChanges changes = new RmResourceChanges(person);
                    try
                    {
                        changes.BeginChanges();

                        //byte[] m_Bytes = ReadToEnd(Uploading);
                        //  person.Photo = Convert.ToInt32(m_Bytes.GetValue(0));

                        using (FileStream writer = new FileStream(upload.FilePath, FileMode.Create))
                        {
                            int readCount;
                            var buffer = new byte[8192];
                            byte[] fileContent = null;
                            BinaryReader binaryReader = new BinaryReader(writer);
          

                            while ((readCount = Uploading.Read(buffer, 0, buffer.Length)) != 0)
                            {
                                writer.Write(buffer, 0, readCount);
                                length += readCount;
                            }
                            // change something in the resource
                            person.Photo = binaryreader;
                        }

                        // modify the resource on the server
                        client.Put(changes);
                        // the operation succeeded: accept the changes.
                        changes.AcceptChanges();
                        // NOTE: after calling AcceptChanges the RmResourceChanges 
                        // object does not contain any more changes to propagate to
                        // the server.
                    }
                    catch (Exception ex)
                    {
                        changes.DiscardChanges();
                    }
                }
                upload.FileLength = length;
                return upload;
            }
        }

Can some one please post the solution to this issue? I need this ASAP.

Thanks,
Sravani
April 27th, 2015 5:40pm

The Server schema has it as base64Binary. In the client code it looks correct
Free Windows Admin Tool Kit Click here and download it now
April 28th, 2015 10:08pm

It's a bug in the FIMClient library (the C# Class RmPerson.cs):

https://fim2010client.codeplex.com/SourceControl/latest#Microsoft.ResourceManagement.ObjectModel/ResourceTypes/RmPerson.cs

public int? Photo { get { return GetNullable<int>(AttributeNames.Photo); } set { SetNullable(AttributeNames.Photo, value); } }

You need to correct it to byte[]. Please also note that the class RmBinary has some issues that may have to be corrected. See:

https://fim2010client.codeplex.com/discussions/258873


April 29th, 2015 3:32am

It's a bug in the FIMClient library (the C# Class RmPerson.cs):

https://fim2010client.codeplex.com/SourceControl/latest#Microsoft.ResourceManagement.ObjectModel/ResourceTypes/RmPerson.cs

public int? Photo { get { return GetNullable<int>(AttributeNames.Photo); } set { SetNullable(AttributeNames.Photo, value); } }

You need to correct it to byte[]. Please also note that the class RmBinary has some issues that may have to be corrected. See:

https://fim2010client.codeplex.com/discussions/258873


Free Windows Admin Tool Kit Click here and download it now
April 29th, 2015 7:32am

It's a bug in the FIMClient library (the C# Class RmPerson.cs):

https://fim2010client.codeplex.com/SourceControl/latest#Microsoft.ResourceManagement.ObjectModel/ResourceTypes/RmPerson.cs

public int? Photo { get { return GetNullable<int>(AttributeNames.Photo); } set { SetNullable(AttributeNames.Photo, value); } }

You need to correct it to byte[]. Please also note that the class RmBinary has some issues that may have to be corrected. See:

https://fim2010client.codeplex.com/discussions/258873


April 29th, 2015 7:32am

Thank you for your reply Leo.

I tried correcting to byte, but did not work. Can you send me the code for the Rm person class modifed.

Sravani

Free Windows Admin Tool Kit Click here and download it now
April 30th, 2015 5:33pm

Thank You David for your reply. I m my code i don't see the Photo attribute as binary in the client code.

Can you send me the code for the Rmperson class where the attributes are defined.

Thanks,

Sravani

April 30th, 2015 5:36pm

Hey ,

I need some in regards with the the upload functionality in FIM portal.

I have a application which updates the user profile where we upload the photo of a person to the FIM 2010 via resource management client  but i could not able do achieve it as the data types are different in the FIM and Rmperson class.

We need to pass binary as per the FIM sync but the definition of the attribute is different as int in resource management dll.

I saw this post in https://fim2010client.codeplex.com/discussions/258873 , and you seem succeeded with the uploading by changing the datatypes.  Can you please share your piece of code where we have to change the Rmperson and Rmbinary, or Rmresource.

Looking forward your reply. 


Thanks in advance,
Sravani
Free Windows Admin Tool Kit Click here and download it now
May 8th, 2015 7:02pm

Hey ,

I need some in regards with the the upload functionality in FIM portal.

I have a application which updates the user profile where we upload the photo of a person to the FIM 2010 via resource management client  but i could not able do achieve it as the data types are different in the FIM and Rmperson class.

We need to pass binary as per the FIM sync but the definition of the attribute is different as int in resource management dll.

I saw this post in https://fim2010client.codeplex.com/discussions/258873 , and you seem succeeded with the uploading by changing the datatypes.  Can you please share your piece of code where we have to change the Rmperson and Rmbinary, or Rmresource.

Looking forward your reply. 


Thanks in advance,
Sravani
May 8th, 2015 11:02pm

Hey ,

I need some in regards with the the upload functionality in FIM portal.

I have a application which updates the user profile where we upload the photo of a person to the FIM 2010 via resource management client  but i could not able do achieve it as the data types are different in the FIM and Rmperson class.

We need to pass binary as per the FIM sync but the definition of the attribute is different as int in resource management dll.

I saw this post in https://fim2010client.codeplex.com/discussions/258873 , and you seem succeeded with the uploading by changing the datatypes.  Can you please share your piece of code where we have to change the Rmperson and Rmbinary, or Rmresource.

Looking forward your reply. 


Thanks in advance,
Sravani
Free Windows Admin Tool Kit Click here and download it now
May 8th, 2015 11:02pm

Hey ,

I need some in regards with the the upload functionality in FIM portal.

I have a application which updates the user profile where we upload the photo of a person to the FIM 2010 via resource management client  but i could not able do achieve it as the data types are different in the FIM and Rmperson class.

We need to pass binary as per the FIM sync but the definition of the attribute is different as int in resource management dll.

I saw this post in https://fim2010client.codeplex.com/discussions/258873 , and you seem succeeded with the uploading by changing the datatypes.  Can you please share your piece of code where we have to change the Rmperson and Rmbinary, or Rmresource.

Looking forward your reply. 


Thanks in advance,
Sravani
May 8th, 2015 11:02pm

Fixed RmBinary.cs

using System;
using System.Text;

namespace Microsoft.ResourceManagement.ObjectModel
{

    public partial class RmBinary : IComparable, IComparable<RmBinary>
    {

        byte[] value;

        /// <summary>
        /// Constructor.
        /// </summary>
        public RmBinary()
        {
            this.value = new byte[0];
        }

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="value">The value.</param>
        public RmBinary(String value)
        {
            this.Value = value;
        }

        public RmBinary(byte[] value)
        {
            this.value = value;
        }

        /// <summary>
        /// The string must be supported by the DateTime class
        /// </summary>
        public String Value
        {
            get
            {
                return Convert.ToBase64String(this.value);
            }
            set
            {
                if (value != null)
                {
                    this.value = Convert.FromBase64String(value);
                }
                else
                {
                    this.value = new byte[0];
                }
            }
        }

        /// <summary>
        /// Gets the value as binary.
        /// </summary>
        /// <value>The value as binary.</value>
        public byte[] ValueAsBinary
        {
            get
            {
                return this.value;
            }
        }

        /// <summary>
        /// Determines whether the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <param name="obj">The <see cref="T:System.Object"/> to compare with the current <see cref="T:System.Object"/>.</param>
        /// <returns>
        /// true if the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>; otherwise, false.
        /// </returns>
        /// <exception cref="T:System.NullReferenceException">
        /// The <paramref name="obj"/> parameter is null.
        /// </exception>
        public override bool Equals(object obj)
        {
            RmBinary other = obj as RmBinary;
            if (other as Object == null)
                return false;
            else
                return this.ToString().Equals(other.ToString());
        }

        /// <summary>
        /// Serves as a hash function for a particular type.
        /// </summary>
        /// <returns>
        /// A hash code for the current <see cref="T:System.Object"/>.
        /// </returns>
        public override int GetHashCode()
        {
            return this.ToString().GetHashCode();
        }

        /// <summary>
        /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </returns>
        public override string ToString()
        {
            return this.Value;
        }

        #region IComparable Members

        /// <summary>
        /// Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
        /// </summary>
        /// <param name="obj">An object to compare with this instance.</param>
        /// <returns>
        /// A 32-bit signed integer that indicates the relative order of the objects being compared. The return value has these meanings:
        /// Value
        /// Meaning
        /// Less than zero
        /// This instance is less than <paramref name="obj"/>.
        /// Zero
        /// This instance is equal to <paramref name="obj"/>.
        /// Greater than zero
        /// This instance is greater than <paramref name="obj"/>.
        /// </returns>
        /// <exception cref="T:System.ArgumentException">
        /// <paramref name="obj"/> is not the same type as this instance.
        /// </exception>
        public int CompareTo(object obj)
        {
            if (obj as Object == null)
                throw new ArgumentNullException("obj");
            return this.CompareTo(obj as RmBinary);
        }

        /// <summary>
        /// The operator ==.
        /// </summary>
        /// <param name="attrib1">The attrib1.</param>
        /// <param name="attrib2">The attrib2.</param>
        /// <returns>The result of the operator.</returns>
        public static bool operator ==(RmBinary attrib1, RmBinary attrib2)
        {
            if (attrib1 as Object == null)
                return false;
            if (attrib2 as Object == null)
                return false;
            return attrib1.CompareTo(attrib2) == 0;
        }

        /// <summary>
        /// The operator !=.
        /// </summary>
        /// <param name="attrib1">The attrib1.</param>
        /// <param name="attrib2">The attrib2.</param>
        /// <returns>The result of the operator.</returns>
        public static bool operator !=(RmBinary attrib1, RmBinary attrib2)
        {
            if (attrib1 == null)
                return false;
            return attrib1.CompareTo(attrib2) != 0;
        }

        /// <summary>
        /// The operator &lt;.
        /// </summary>
        /// <param name="attrib1">The attrib1.</param>
        /// <param name="attrib2">The attrib2.</param>
        /// <returns>The result of the operator.</returns>
        public static bool operator <(RmBinary attrib1, RmBinary attrib2)
        {
            if (attrib1 == null)
                return false;
            return attrib1.CompareTo(attrib2) < 0;
        }

        /// <summary>
        /// The operator &gt;.
        /// </summary>
        /// <param name="attrib1">The attrib1.</param>
        /// <param name="attrib2">The attrib2.</param>
        /// <returns>The result of the operator.</returns>
        public static bool operator >(RmBinary attrib1, RmBinary attrib2)
        {
            if (attrib1 == null)
                return false;
            return attrib1.CompareTo(attrib2) > 0;
        }

        /// <summary>
        /// The operator &lt;=.
        /// </summary>
        /// <param name="attrib1">The attrib1.</param>
        /// <param name="attrib2">The attrib2.</param>
        /// <returns>The result of the operator.</returns>
        public static bool operator <=(RmBinary attrib1, RmBinary attrib2)
        {
            if (attrib1 == null)
                return false;
            return attrib1.CompareTo(attrib2) <= 0;
        }

        /// <summary>
        /// The operator &gt;=.
        /// </summary>
        /// <param name="attrib1">The attrib1.</param>
        /// <param name="attrib2">The attrib2.</param>
        /// <returns>The result of the operator.</returns>
        public static bool operator >=(RmBinary attrib1, RmBinary attrib2)
        {
            if (attrib1 == null)
                return false;
            return attrib1.CompareTo(attrib2) >= 0;
        }

        #endregion

        #region IComparable<RmBinary> Members

        /// <summary>
        /// Compares the current object with another object of the same type.
        /// </summary>
        /// <param name="other">An object to compare with this object.</param>
        /// <returns>
        /// A 32-bit signed integer that indicates the relative order of the objects being compared. The return value has the following meanings:
        /// Value
        /// Meaning
        /// Less than zero
        /// This object is less than the <paramref name="other"/> parameter.
        /// Zero
        /// This object is equal to <paramref name="other"/>.
        /// Greater than zero
        /// This object is greater than <paramref name="other"/>.
        /// </returns>
        public int CompareTo(RmBinary other)
        {
            if (other == null)
                throw new ArgumentNullException("other");
            else
                return this.ToString().CompareTo(other.ToString());

        }

        #endregion
    }
}


Free Windows Admin Tool Kit Click here and download it now
June 17th, 2015 12:40pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics